<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use EasyWeChat;

class UserController extends Controller
{
    public function __construct()
    {
        $this->middleware('wechat.oauth', ['only' => ['index']]);
    }

    public function login (Request $req) {
        if($req->session()->get('wechat.oauth_user') ) {
            return redirect('/user');
        }

        return redirect('/user');
    }

    public function index(Request $req)
    {
        $user = $req->session()->get('wechat.oauth_user'); // 拿到授权用户资料
        dd($user);
    }

    public function logout(Request $req) {
        $req->session()->forget('wechat.oauth_user');
        echo 'logout ok';
    }
}
